package com.sgcc.ln.pmos.e_ln_mall.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.ln.pmos.common.utils.BigDecimalUtils;
import com.sgcc.ln.pmos.common.utils.DateUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.e_ln_mall.bean.InvitationListBean;


public class InvitationListAdapter extends BaseQuickAdapter<InvitationListBean.DataDTO.ListDTO, BaseViewHolder> {


    public InvitationListAdapter() {
        super(R.layout.item_invitation_list);
    }

    private OnBtnClickListener mOnBtnClickListener;

    public interface OnBtnClickListener {
        void deleteBtn(int position, InvitationListBean.DataDTO.ListDTO data);

        void editBtn(int osition, InvitationListBean.DataDTO.ListDTO data);

        void upOrDownBtn(int osition, InvitationListBean.DataDTO.ListDTO data);
    }

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        mOnBtnClickListener = onBtnClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, InvitationListBean.DataDTO.ListDTO bean) {

        baseViewHolder.setText(R.id.tv_updatetime, "更新时间：" + DateUtils.getStrng_to_Times_ymd_5(bean.getUpdateDate()));
        baseViewHolder.setText(R.id.tvName, bean.getMembersUsersName());
        baseViewHolder.setText(R.id.tvCycle, DateUtils.getStrng_to_Times_ymd_3(bean.getIntentionStartDate())
                + "至" + DateUtils.getStrng_to_Times_ymd_3(bean.getIntentionEndDate()));
        baseViewHolder.setText(R.id.tvHistoryPower, BigDecimalUtils.onKeep3Decimal(bean.getYearEnergyAvg()) + "MWh");
        baseViewHolder.setText(R.id.tvUserMonthEnergy, TextUtils.isEmpty(bean.getUserMonthEnergy())
                ? "" : BigDecimalUtils.onKeep3Decimal(bean.getUserMonthEnergy()) + "MWh");
        baseViewHolder.setText(R.id.tvContactName, bean.getContactName());
        baseViewHolder.setText(R.id.tvContactPhone, bean.getContactPhone());
        baseViewHolder.setText(R.id.tvIsDayparting, bean.getIsDaypartingStr());
        baseViewHolder.setText(R.id.tvIsPredeterminedEnergy, bean.getIsPredeterminedEnergyStr());
        baseViewHolder.setText(R.id.tvIsInterlock, bean.getIsInterlockStr());
        baseViewHolder.setText(R.id.tvTerminationType, bean.getTerminationTypeStr());
        baseViewHolder.setText(R.id.tvStauts, bean.getStautsStr());
        baseViewHolder.setText(R.id.tvValidity, bean.getDurationDay());


        baseViewHolder.setGone(R.id.tv_delete, bean.getStauts() == 1);
        baseViewHolder.setGone(R.id.tv_edit, bean.getStauts() == 1);

        baseViewHolder.setText(R.id.tv_upordown, bean.getStauts() == 1 ? "撤销" : "发布");


        baseViewHolder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnBtnClickListener != null) {
                    mOnBtnClickListener.deleteBtn(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_upordown).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnBtnClickListener != null) {
                    mOnBtnClickListener.upOrDownBtn(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnBtnClickListener != null) {
                    mOnBtnClickListener.editBtn(getItemPosition(bean), bean);
                }
            }
        });
    }
}
